import React, { Component } from 'react'
import PropTypes from 'prop-types'

export default class Child extends Component {
  static propTypes = {
    colors: PropTypes.array.isRequired,
    age: PropTypes.number,
    // obj: PropTypes.object,
    obj: PropTypes.shape({
      address: PropTypes.string,
      age: PropTypes.number.isRequired,
    }),
    jsx: PropTypes.element,
  }
  render() {
    return (
      <div>
        Child
        <ul>
          {this.props.colors.map((item) => (
            <li key={item} style={{ backgroundColor: item }}>
              {item}
            </li>
          ))}
        </ul>
        <p>age: {this.props.age}</p>
        <p>address: {this.props.obj.address}</p>
      </div>
    )
  }
}

// 静态属性
/* Child.propTypes = {
  colors: PropTypes.array,
} */
